<?php
    class Default_Model_News extends Zend_Db_Table_Abstract
    {
        protected $_name = 'news';
        protected $_primary = 'news_id';
        protected $_newComent='news_comment';
        protected $_db;
        
        public function __construct() {
            $this->_db = Zend_Registry::get('db');
        }
        
        public function listNews() {
            $data = array(
                'news_id',
                'news_title',
                'news_image',
                'create_date',
                'news_plaintext',
            );
            $sql = $this->_db->select()
                            ->from($this->_name, $data)
                            ->where('status = 1')
                            ->order('news_id DESC');
            return $sql;
        }
        public function listcomment($news_id){
            $sql ="select  news_comment_id,news_comment_content,create_date,user.fullname,user.avatar from news_comment  inner join user on news_comment.user_id = user.user_id where news_comment.status=1 and news_comment.news_id =$news_id";
            $result = $this->_db->fetchAll($sql);
            return $result;
        }
        public function listNewsLimit() {
            $sql ="SELECT * FROM news where status=1 order by news_id DESC limit 7";
           return $this->_db->fetchAll($sql);
        }
        public function NewsDetails($news_id) {
                $sql = $this->_db->select()
                                ->from($this->_name)
                                ->where('news_id =?', $news_id);                              
                $result = $this->_db->fetchAll($sql);
                return $result;

        }
        public function addNewsComment($data){
            $sql = $this->_db->insert($this->_newComent, $data);
            $result = $this->_db->lastInsertId($this->_name);
            return $result;
        }
    }
